package com.lingo.ffmpegdemo.springdemo.demo;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @Author watson
 * @Date 2022/6/8 20:12
 * @Description: 实现ImportBeanDefinitionRegistrar接口，
 * 重写registerBeanDefinitions方法，
 * 手动注册bean；同时实现一些Aware接口，以便获取Spring的一些数据。
 * @Version 1.0
 */
public class MapperAutoConfiguredMyBatisRegistrar implements
        ImportBeanDefinitionRegistrar, ResourceLoaderAware, BeanFactoryAware {

    private ResourceLoader resourceLoader;
    private BeanFactory beanFactory;

    /**
     * @return void
     * @Author haien
     * @Description 注册bean，但我们并不知道需要注册哪些bean，所以需要借助
     * ClassPathBeanDefinitionScanner扫描器，扫描我们需要注册的bean
     * @Date 2019/6/11
     * @Param [annotationMetadata, beanDefinitionRegistry]
     **/
    @Override
    public void registerBeanDefinitions(AnnotationMetadata annotationMetadata,
                                        BeanDefinitionRegistry registry) {

        MyClasssPathBeanDefinitionScanner scanner =
                new MyClasssPathBeanDefinitionScanner(registry, false);
        scanner.setResourceLoader(resourceLoader);
        scanner.registerFilters();
        scanner.doScan("com.lingo.ffmpegdemo.springdemo.demo");
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
    }

    @Override
    public void setResourceLoader(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;
    }

}
